<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Context Free LALR1 compiler: src/contextFree/scanner/State.java Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Context Free LALR1 compiler
   &#160;<span id="projectnumber">1.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="dynsections.js"></script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_state_8java.html','');
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">src/contextFree/scanner/State.java</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="keyword">package </span>contextFree.scanner;
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="keyword">import</span> java.util.Hashtable;
<a name="l00004"></a>00004 <span class="keyword">import</span> java.util.Iterator;
<a name="l00005"></a>00005 <span class="keyword">import</span> java.util.LinkedList;
<a name="l00006"></a>00006 <span class="keyword">import</span> java.util.List;
<a name="l00007"></a>00007 
<a name="l00008"></a><a class="code" href="classcontext_free_1_1scanner_1_1_state.html">00008</a> <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a> {
<a name="l00009"></a>00009         <span class="keyword">private</span> <span class="keywordtype">int</span> index;
<a name="l00010"></a>00010         <span class="keyword">private</span> List&lt;IndexedProduction&gt; items;
<a name="l00011"></a>00011         <span class="keyword">private</span> Hashtable&lt;String, Integer&gt; shift;
<a name="l00012"></a>00012 
<a name="l00016"></a><a class="code" href="classcontext_free_1_1scanner_1_1_state.html#ae93b8be2177c617058502abfcfce5204">00016</a>         <span class="keyword">public</span> <a class="code" href="classcontext_free_1_1scanner_1_1_state.html#ae93b8be2177c617058502abfcfce5204" title="constructor state 0">State</a>(){
<a name="l00017"></a>00017                 this.index=0;
<a name="l00018"></a>00018                 this.items = <span class="keyword">new</span> LinkedList&lt;IndexedProduction&gt;();
<a name="l00019"></a>00019                 this.shift = <span class="keyword">new</span> Hashtable&lt;String, Integer&gt;();
<a name="l00020"></a>00020         }
<a name="l00021"></a>00021         
<a name="l00026"></a><a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a81cd656c8ed26ba10aedd6598d090dcc">00026</a>         <span class="keyword">public</span> <a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a81cd656c8ed26ba10aedd6598d090dcc" title="constructor state i-th, with empty list productions">State</a>(<span class="keywordtype">int</span> i){
<a name="l00027"></a>00027                 this.index=i;
<a name="l00028"></a>00028                 this.items = <span class="keyword">new</span> LinkedList&lt;IndexedProduction&gt;();
<a name="l00029"></a>00029                 this.shift = <span class="keyword">new</span> Hashtable&lt;String, Integer&gt;();
<a name="l00030"></a>00030         }
<a name="l00031"></a>00031         
<a name="l00037"></a><a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a8dc8e0da9fdc805b0202f66eebce1e57">00037</a>         <span class="keyword">public</span> <a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a8dc8e0da9fdc805b0202f66eebce1e57" title="constructor state i-th, whit list production c">State</a>(<span class="keywordtype">int</span> i, List&lt;IndexedProduction&gt; c){
<a name="l00038"></a>00038                 this.index=i;
<a name="l00039"></a>00039                 this.items = c;
<a name="l00040"></a>00040                 this.shift = <span class="keyword">new</span> Hashtable&lt;String, Integer&gt;();
<a name="l00041"></a>00041         }
<a name="l00042"></a>00042         
<a name="l00049"></a><a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a7ab62a86fa7c7072e898d9b8ab1b3cd5">00049</a>         <span class="keyword">public</span> <a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a7ab62a86fa7c7072e898d9b8ab1b3cd5" title="constructor state i-th, whit list production c and list of lookahead">State</a>(<span class="keywordtype">int</span> i, List&lt;IndexedProduction&gt; c, Hashtable&lt;String, Integer&gt; table){
<a name="l00050"></a>00050                 this.index=i;
<a name="l00051"></a>00051                 this.items = c;
<a name="l00052"></a>00052                 this.shift = <span class="keyword">new</span> Hashtable&lt;String, Integer&gt;(table);
<a name="l00053"></a>00053         }
<a name="l00054"></a>00054         
<a name="l00055"></a>00055         <span class="keyword">public</span> List&lt;IndexedProduction&gt; getItems() {
<a name="l00056"></a>00056                 <span class="keywordflow">return</span> items;
<a name="l00057"></a>00057         }
<a name="l00058"></a>00058 
<a name="l00059"></a>00059         <span class="keyword">public</span> <span class="keywordtype">void</span> setItems(List&lt;IndexedProduction&gt; Items) {
<a name="l00060"></a>00060                 this.items = Items;
<a name="l00061"></a>00061         }
<a name="l00062"></a>00062         
<a name="l00063"></a>00063         <span class="keyword">public</span> Hashtable&lt;String, Integer&gt; getShift() {
<a name="l00064"></a>00064                 <span class="keywordflow">return</span> shift;
<a name="l00065"></a>00065         }
<a name="l00066"></a>00066 
<a name="l00067"></a>00067         <span class="keyword">public</span> <span class="keywordtype">void</span> setShift(Hashtable&lt;String, Integer&gt; shift) {
<a name="l00068"></a>00068                 this.shift = shift;
<a name="l00069"></a>00069         }
<a name="l00070"></a>00070 
<a name="l00071"></a>00071         <span class="keyword">public</span> <span class="keywordtype">int</span> getIndex() {
<a name="l00072"></a>00072                 <span class="keywordflow">return</span> index;
<a name="l00073"></a>00073         }
<a name="l00074"></a>00074 
<a name="l00075"></a>00075         <span class="keyword">public</span> <span class="keywordtype">void</span> setIndex(<span class="keywordtype">int</span> index) {
<a name="l00076"></a>00076                 this.index = index;
<a name="l00077"></a>00077         }
<a name="l00078"></a>00078         
<a name="l00079"></a>00079         
<a name="l00084"></a><a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a5259b186755c072d90d06dceb2b756ac">00084</a>         <span class="keyword">public</span> Integer <a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a5259b186755c072d90d06dceb2b756ac" title="Return the index of the state shifted with a specific simbol.">gotoStateIndex</a>(String simbol){
<a name="l00085"></a>00085                 <span class="keywordflow">try</span>{
<a name="l00086"></a>00086                         <span class="keywordflow">return</span> this.shift.get(simbol);
<a name="l00087"></a>00087                 }<span class="keywordflow">catch</span> (Exception e) {
<a name="l00088"></a>00088                         <span class="keywordflow">return</span> null;
<a name="l00089"></a>00089                 }
<a name="l00090"></a>00090         }
<a name="l00091"></a>00091         
<a name="l00097"></a><a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a987d4c7ae8eb2754f13f0099f5d861a5">00097</a>         <span class="keyword">public</span> List&lt;IndexedProduction&gt; <a class="code" href="classcontext_free_1_1scanner_1_1_state.html#a987d4c7ae8eb2754f13f0099f5d861a5" title="return one list&lt;IndexedProduction&gt; with the kernel of a state">getKernels</a>(){
<a name="l00098"></a>00098                  <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> prod = <span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a>();
<a name="l00099"></a>00099                 List&lt;IndexedProduction&gt; j =<span class="keyword">new</span> LinkedList&lt;IndexedProduction&gt;();
<a name="l00100"></a>00100                 <span class="comment">//se ci troviamo nello stato 0</span>
<a name="l00101"></a>00101                 <span class="keywordflow">if</span>(index==0){
<a name="l00102"></a>00102                         <span class="comment">//solo la produzione S&#39;::=S appartiene al kernel</span>
<a name="l00103"></a>00103                          Iterator&lt;IndexedProduction&gt; it = items.iterator();
<a name="l00104"></a>00104                          <span class="comment">//per ogni item dello stato</span>
<a name="l00105"></a>00105                          <span class="keywordflow">while</span>(it.hasNext()){
<a name="l00106"></a>00106                                  prod = it.next();
<a name="l00107"></a>00107                                  j.add(prod);
<a name="l00108"></a>00108                                  <span class="keywordflow">break</span>;
<a name="l00109"></a>00109                          }
<a name="l00110"></a>00110                 }
<a name="l00111"></a>00111                 <span class="comment">//se non siamo nello stato 0</span>
<a name="l00112"></a>00112                  <span class="keywordflow">else</span>{
<a name="l00113"></a>00113                          Iterator&lt;IndexedProduction&gt; it = items.iterator();
<a name="l00114"></a>00114                          <span class="comment">//per ogni item dello stato</span>
<a name="l00115"></a>00115                          <span class="keywordflow">while</span>(it.hasNext()){
<a name="l00116"></a>00116                                  prod = it.next();
<a name="l00117"></a>00117                                  <span class="comment">//vediamo in che posizione si trova il puntino, perch� solo le produzionioni che hanno il </span>
<a name="l00118"></a>00118                                  <span class="comment">//puntino in una posizione diversa dalla prima faranno parte del kernel</span>
<a name="l00119"></a>00119                                  <span class="keywordflow">if</span>(prod.getCurrentCharIndex()!=0){
<a name="l00120"></a>00120                                         <span class="comment">//quindi la aggiungiamo a J</span>
<a name="l00121"></a>00121                                          <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> p = <span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a>(prod);
<a name="l00122"></a>00122                                          p.<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html#a45b191078f89a67427a2593b67ae4f1e">getLookahead</a>().addAll(prod.<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html#a45b191078f89a67427a2593b67ae4f1e">getLookahead</a>());
<a name="l00123"></a>00123                                          j.add(p);
<a name="l00124"></a>00124                                  }
<a name="l00125"></a>00125                          }
<a name="l00126"></a>00126                  }
<a name="l00127"></a>00127                 <span class="keywordflow">return</span> j;
<a name="l00128"></a>00128         }
<a name="l00129"></a>00129         
<a name="l00130"></a>00130         @Override
<a name="l00131"></a>00131         <span class="keyword">public</span> String toString(){
<a name="l00132"></a>00132                 String result= <span class="stringliteral">&quot;\nState number: &quot;</span>+index+<span class="stringliteral">&quot;\t&quot;</span>;
<a name="l00133"></a>00133                 <span class="keywordflow">if</span>(shift.values().size()!=0)
<a name="l00134"></a>00134                         result+=<span class="stringliteral">&quot; | goto&quot;</span>+shift.values().toString()+<span class="stringliteral">&quot;\n&quot;</span>;
<a name="l00135"></a>00135                 <span class="keywordflow">for</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> i : items){
<a name="l00136"></a>00136                         result += i.toString() + <span class="stringliteral">&quot;\n&quot;</span>;
<a name="l00137"></a>00137                 }
<a name="l00138"></a>00138                 <span class="keywordflow">return</span> result;          
<a name="l00139"></a>00139         }
<a name="l00140"></a>00140 
<a name="l00141"></a>00141         <span class="keyword">public</span> <span class="keywordtype">int</span> size() {
<a name="l00142"></a>00142                 <span class="keywordflow">return</span> items.size();
<a name="l00143"></a>00143         }
<a name="l00144"></a>00144         
<a name="l00145"></a>00145 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>State.java</b>      </li>

    <li class="footer">Generated on Fri Mar 30 2012 21:26:24 for Context Free LALR1 compiler by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
